import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.less'
export default class Header extends Component {
  handleKeyUp = (e) => {
    let { keyCode, target } = e
    if (keyCode == 13 && target.value !== '') {
      //把子组件需要传递给父组件的内容作为函数的参数，通过调用父组件传递的函数的形式来给父组件传递子组件想要传递的内容
      this.props.handleValue(target.value)
      target.value = ''
    }
  }
  render() {
    return (
      <div className='todo-header'>
        <input type="text" placeholder='请输入您的任务名称，按回车确认' onKeyUp={this.handleKeyUp} />
      </div>
    )
  }
  //对接收的props进行类型以及必要性的限制
  static propTypes = {
    handleValue:PropTypes.func.isRequired
  }
}
